package com.sc.common.util;

import com.sc.common.constant.AuthConst;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

public class UserUtils {
    /**
     * 获取登录用户信息
     * @return
     */
    public static String getUser(){
        String user=null;
             user = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()
                    .getHeader(AuthConst.AUTH_USER);

        return StringUtils.isBlank(user)?"admin":user;
    }
    public static Long getUserId(){
        String user=null;
        user = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()
                .getHeader(AuthConst.Auth_Id);

        return StringUtils.isBlank(user)?1:Long.parseLong(user);
    }

}
